﻿<?php  
GLOBAL $CFG;
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/local/blackboxsurvey/lib.php');
require_once($CFG->dirroot . "/course/publish/lib.php");


$dir = $CFG->wwwroot.'/local/blackboxsurvey/';
//==================load mycss========================
echo '<link rel="stylesheet" href="'.$dir.'css/mycss.css" type="text/css" media="screen" />';
//==================start colorbox=================
echo '<script src="'.$dir.'colorbox/jquery.min.js"></script>';
echo '<link rel="stylesheet" href="'.$dir.'css/colorbox.css" />';
echo '<script src="'.$dir.'colorbox/jquery.colorbox.js"></script>';
//==================load module.js========================
echo '<script src="'.$dir.'module.js"></script>';
//==================end load js=================

echo '<script>
			$(document).ready(function(){
				$(".iframe").colorbox({iframe:true, width:"60%", height:"80%", onClosed:function(){location.reload(true); }});
			});
		</script>';	

/*echo '<script language="javascript" type="text/javascript" src="'.$dir.'arborjs/jquery.min.js"></script>
        <script language="javascript" type="text/javascript" src="'.$dir.'arborjs/arbor.js" ></script>
        <script language="javascript" type="text/javascript" src="'.$dir.'arborjs/graphics.js" ></script>
        <script language="javascript" type="text/javascript" src="'.$dir.'arborjs/renderer.js" ></script>';*/
$jsmodule = array(
    'name'  =>  'local_blackboxsurvey',
    'fullpath'  =>  '/local/blackboxsurvey/module.js',
    'requires'  =>  array('base', 'node', 'io', 'json')
);

/*echo  '<link rel="stylesheet" href="./treeview/jquery.treeview.css" />
		 <script src="./treeview/lib/jquery.cookie.js" type="text/javascript"></script>
		 <script src="./treeview/jquery.treeview.js" type="text/javascript"></script>';*/
//******************************************************************************************************************************************************************
//                                                                              FORM MATCHING MANAGEMENT
//******************************************************************************************************************************************************************
class form_view_matching_result extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $path_image = $this->_customdata['path_image'];
        $program = $this->_customdata['program'];
        $subject = $this->_customdata['subject'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        
        $prerequisite_subject = $this->_customdata['prerequisite_subject'];
        $input_detail = $this->_customdata['input_detail'];
        $receive_subject = $this->_customdata['receive_subject'];
        $output_detail = $this->_customdata['output_detail'];
        
        //hien thong tin co ban
        $display_index = 'b_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('basic_info', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;display:none;">
                                    <table border=0>
                            		<tr><td class="headingblock header" width=150px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
                                    <tr><td class="headingblock header" width=150px>'.get_string('subject', 'local_blackboxsurvey').'</td><td>'.$subject.'</td></tr>
                            		<tr><td class="headingblock header" width=150px>'.get_string('begindate', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
                            		<tr><td class="headingblock header" width=150px>'.get_string('enddate', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table>
                                    </div>');
                                    
        //hien thi prerequisite subject
        $display_index = 'prerequisite';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                            <img id="show'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            <img id="hide'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            '.get_string('prerequisite_subject', 'local_blackboxsurvey').'
                            </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1 style="display:none;">'.$prerequisite_subject.'</div>');
        
        //hien thi input relationship
        $display_index = 'input';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                            <img id="show'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            <img id="hide'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            '.get_string('input_detail', 'local_blackboxsurvey').'
                            </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1 style="display:none;">'.$input_detail.'</div>');
        
        //hien thi receive subject subject
        $display_index = 'receive';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                            <img id="show'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            <img id="hide'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            '.get_string('receive_subject', 'local_blackboxsurvey').'
                            </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1 style="display:none;">'.$receive_subject.'</div>');
        
        //hien thi ouput relationship
        $display_index = 'output';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                            <img id="show'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            <img id="hide'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            '.get_string('output_detail', 'local_blackboxsurvey').'
                            </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1 style="display:none;">'.$output_detail.'</div>');
    }
}
//Form manage blackbos survey
class form_course_map extends moodleform {
	public function definition() {
		$mform = $this->_form;
        
        $str = $this->_customdata['str'];
        //echo "<script>alert('".$str."');</script>";
        //$mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');

		$mform->addElement('html','<div id="course_map">'.
            '<canvas id="viewport" width="1000" height="600"></canvas>
            <script language="javascript" type="text/javascript">
            
            var sys = arbor.ParticleSystem(1000, 400,1);
            sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015})
            sys.renderer = Renderer("#viewport") ;
            
            var project = sys.addNode(1,{color:"gray","shape":"dot",label:"Blackbox survey",link:""});
            var luan = sys.addNode(2,{color:"#95cde5","shape":"block",label:"Luan",link:""});
            var hoang = sys.addNode(3,{color:"#b01700","shape":"dependencia",label:"Hoang"});
            var giang = sys.addNode(4,{color:"red","shape":"block",label:"Giang"});
            
            sys.addEdge(project,luan, {directed:{edge:"->"},color:"green",name:"Project Manager",font:"italic 13px sans-serif"})
            sys.addEdge(project,hoang, {directed:{edge:"->"},color:"blue",name:"Tester",font:"italic 13px sans-serif"})
            sys.addEdge(project,giang, {directed:{edge:"->"},color:"red",name:"Designer"})
            </script>'
        .'</div>');
	}
}

//Form matching subject
class form_matching_subject extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $num_qn = $this->_customdata['num_qn'];//so luong phieu khao sat
		$program = $this->_customdata['program'];
        $path_image = $this->_customdata['path_image'];
        $subject = $this->_customdata['subject'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        $num_ques = $this->_customdata['ques_num'];
        $matching_content = $this->_customdata['matching_content'];
        $accepted_request = $this->_customdata['accepted_request'];
        $id_matching = $this->_customdata['id_matching'];
        $check_admin = $this->_customdata['check_admin'];
        
        $mform->addElement('html', '<input type="submit" value="'.get_string('save', 'local_blackboxsurvey').'" onclick="return confirm_save_matching_subject('."'".get_string('save_match_alert', 'local_blackboxsurvey')."'".');">');
        //hien thong tin co ban
        $display_index = 'b_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('basic_info', 'local_blackboxsurvey').
                                    '</div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'">
                                    <table border=0>
                            		<tr><td class="headingblock header" width=150px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
                                    <tr><td class="headingblock header" width=150px>'.get_string('subject', 'local_blackboxsurvey').'</td><td>'.$subject.'</td></tr>
                            		<tr><td class="headingblock header" width=150px>'.get_string('begindate', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
                            		<tr><td class="headingblock header" width=150px>'.get_string('enddate', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table>
                                    </div>');
                                    
        //hien phan tra loi cau hoi
        for($k=1;$k<=$num_qn;$k++)
        {
    		$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;" >
                                        <img id="show'.$k.'" style="cursor:pointer;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('.$k.');"/>
                                        <img id="hide'.$k.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('.$k.');"/>
                                        '.get_string('question_ans', 'local_blackboxsurvey').$this->_customdata['surveyor'.$k].'</div></p>');
            $qn_id = $this->_customdata['qn_id'.$k];
            $mform->addElement('html', '<div id="display_content'.$k.'" style="display:none;">');
            for($i=1;$i<=$num_ques;$i++)
            {
                $q = $this->_customdata['ques_content'.$i];
                $mform->addElement('html', '<br/><h5>'.$q.'</h5>');
                
                //save lai id va dang cua tung cau hoi
                $ques_type = $this->_customdata['type'.$i];
                $ques_id = $this->_customdata['ques_id'.$i];
                /*$ques_id_type .= '<br><input type="checkbox" name="ques_id[]" checked="checked" value="'.$ques_id.'"> '.$ques_id.
                                '<input type="checkbox" name="ques_type[]" checked="checked" value="'.$ques_type.'"> '.$ques_type;*/
                
                //hi?n khung tra l?i cau h?i
                if($ques_type == 1){
                    $ans = $this->_customdata['ans'.$qn_id.$i];
                    $mform->addElement('html', '<textarea disabled name="ques_ans'.$qn_id.$i.'" cols="30" rows="5" style="width: 277px; height: 101px;">'.$ans.'</textarea><br/>'); 
                }
                //multichoice question - many answer - checkbox
                elseif($ques_type == 2){
                    $m = $this->_customdata['num_choice'.$i];
                    for($j = 1;$j<=$m;$j++)
                    {
                        $opt_id = $this->_customdata['choice_id'.$i.$j];
                        $opt_content = $this->_customdata['choice_content'.$i.$j];
                        $checked = $this->_customdata['choice_ck'.$qn_id.$i.$j];
                        $mform->addElement('html', '<input disabled type="checkbox" '.$checked.' name="ques_ans'.$qn_id.$i.'[]" value="'.$opt_id.'"> '.$opt_content.'<br>');
                    }
                }
                //multichoice question - single answer - radio
                elseif ($ques_type == 3){
                    $m = $this->_customdata['num_choice'.$i];

                    $radioarray=array();
                    for($j = 1;$j<=$m;$j++)
                    {
                        $opt_id = $this->_customdata['choice_id'.$i.$j];
                        $opt_content = $this->_customdata['choice_content'.$i.$j];
                        $checked = $this->_customdata['choice_ck'.$qn_id.$i.$j];
                        //echo "<script type='text/javascript'>alert('".$k.$i.$j.$checked."');</script>";
                        $mform->addElement('html', '<input disabled type="radio" '.$checked.' name="ques_ans'.$qn_id.$i.'" value="'.$opt_id.'"> '.$opt_content.'<br>'); 
                    }
                    $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
                }
                //hien yes no question
                elseif ($ques_type == 4){
                    $ans = $this->_customdata['ans'.$qn_id.$i];
                    if($ans == 0)
                        $select0 = 'selected';
                    elseif($ans == 1)
                        $select1 = 'selected';
                    $mform->addElement('html', '<select disabled name="ques_ans'.$qn_id.$i.'">
                                                <option '.$select0.' value="0">No</option>
                                                <option '.$select1.' value="1">Yes</option>
                                                </select>'); 
                }
                $mform->addElement('html', '<br/>');
            }
            $mform->addElement('html', '</div>');
        }
        //hien thi accepted output
        $display_index = 'accepted';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                            <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            '.get_string('accepted_output', 'local_blackboxsurvey').'
                            </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1>'.$accepted_request.'</div>');
        
        //hien thi matching table
        $display_index = 'matching';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                                    <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                    <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                    '.get_string('matching_info', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1><div id="matching_table">'.$matching_content.'</div></div>');
        $mform->addElement('html', '<input type="submit" value="'.get_string('save', 'local_blackboxsurvey').'" onclick="return confirm_save_matching_subject('."'".get_string('save_match_alert', 'local_blackboxsurvey')."'".');">');
        $mform->addElement('html','<div style="display:none">');    
        $mform->addElement('text', 'id_matching', 'id_matching', array());
        $mform->setDefault('id_matching', $id_matching);
        $mform->addElement('text', 'check_admin', 'check_admin', array());
        $mform->setDefault('check_admin', $check_admin);
        $mform->addElement('html','</div>');    
        
        
    }
}

//Form view matching subject
class form_view_matching_subject extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $num_qn = $this->_customdata['num_qn'];//so luong phieu khao sat
		$program = $this->_customdata['program'];
        $path_image = $this->_customdata['path_image'];
        $subject = $this->_customdata['subject'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        $num_ques = $this->_customdata['ques_num'];
        $matching_content = $this->_customdata['matching_content'];
        $accepted_request = $this->_customdata['accepted_request'];
        $id_matching = $this->_customdata['id_matching'];
        $check_admin = $this->_customdata['check_admin'];
        
        //$mform->addElement('html', '<input type="submit" value="Save" onclick="return confirm_save_matching_subject();">');
        //hien thong tin co ban
        $display_index = 'b_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('basic_info', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'">
                                    <table border=0>
                            		<tr><td class="headingblock header" width=150px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
                                    <tr><td class="headingblock header" width=150px>'.get_string('subject', 'local_blackboxsurvey').'</td><td>'.$subject.'</td></tr>
                            		<tr><td class="headingblock header" width=150px>'.get_string('begindate', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
                            		<tr><td class="headingblock header" width=150px>'.get_string('enddate', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table>
                                    </div>');
                                    
        //hien phan tra loi cau hoi
        for($k=1;$k<=$num_qn;$k++)
        {
    		$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;" >
                                        <img id="show'.$k.'" style="cursor:pointer;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('.$k.');"/>
                                        <img id="hide'.$k.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('.$k.');"/>
                                        '.get_string('question_ans', 'local_blackboxsurvey').$this->_customdata['surveyor'.$k].'</div></p>');
            $qn_id = $this->_customdata['qn_id'.$k];
            $mform->addElement('html', '<div id="display_content'.$k.'" style="display:none;">');
            for($i=1;$i<=$num_ques;$i++)
            {
                $q = $this->_customdata['ques_content'.$i];
                $mform->addElement('html', '<br/><h5>'.$q.'</h5>');
                
                //save lai id va dang cua tung cau hoi
                $ques_type = $this->_customdata['type'.$i];
                $ques_id = $this->_customdata['ques_id'.$i];
                /*$ques_id_type .= '<br><input type="checkbox" name="ques_id[]" checked="checked" value="'.$ques_id.'"> '.$ques_id.
                                '<input type="checkbox" name="ques_type[]" checked="checked" value="'.$ques_type.'"> '.$ques_type;*/
                
                //hi?n khung tra l?i cau h?i
                if($ques_type == 1){
                    $ans = $this->_customdata['ans'.$qn_id.$i];
                    $mform->addElement('html', '<textarea disabled name="ques_ans'.$qn_id.$i.'" cols="30" rows="5" style="width: 277px; height: 101px;">'.$ans.'</textarea><br/>'); 
                }
                //multichoice question - many answer - checkbox
                elseif($ques_type == 2){
                    $m = $this->_customdata['num_choice'.$i];
                    for($j = 1;$j<=$m;$j++)
                    {
                        $opt_id = $this->_customdata['choice_id'.$i.$j];
                        $opt_content = $this->_customdata['choice_content'.$i.$j];
                        $checked = $this->_customdata['choice_ck'.$qn_id.$i.$j];
                        $mform->addElement('html', '<input disabled type="checkbox" '.$checked.' name="ques_ans'.$qn_id.$i.'[]" value="'.$opt_id.'"> '.$opt_content.'<br>');
                    }
                }
                //multichoice question - single answer - radio
                elseif ($ques_type == 3){
                    $m = $this->_customdata['num_choice'.$i];

                    $radioarray=array();
                    for($j = 1;$j<=$m;$j++)
                    {
                        $opt_id = $this->_customdata['choice_id'.$i.$j];
                        $opt_content = $this->_customdata['choice_content'.$i.$j];
                        $checked = $this->_customdata['choice_ck'.$qn_id.$i.$j];
                        //echo "<script type='text/javascript'>alert('".$k.$i.$j.$checked."');</script>";
                        $mform->addElement('html', '<input disabled type="radio" '.$checked.' name="ques_ans'.$qn_id.$i.'" value="'.$opt_id.'"> '.$opt_content.'<br>'); 
                    }
                    $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
                }
                //hien yes no question
                elseif ($ques_type == 4){
                    $ans = $this->_customdata['ans'.$qn_id.$i];
                    if($ans == 0)
                        $select0 = 'selected';
                    elseif($ans == 1)
                        $select1 = 'selected';
                    $mform->addElement('html', '<select disabled name="ques_ans'.$qn_id.$i.'">
                                                <option '.$select0.' value="0">No</option>
                                                <option '.$select1.' value="1">Yes</option>
                                                </select>'); 
                }
                $mform->addElement('html', '<br/>');
            }
            $mform->addElement('html', '</div>');
        }
        //hien thi accepted output
        $display_index = 'accepted';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                            <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                            '.get_string('accepted_output', 'local_blackboxsurvey').'
                            </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1>'.$accepted_request.'</div>');
        
        //hien thi matching table
        $display_index = 'matching';
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">
                                    <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                    <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                    '.get_string('matching_info', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" border=1>'.$matching_content.'</div>');
        
        $mform->addElement('html','<div style="display:none">');    
        $mform->addElement('text', 'id_matching', 'id_matching', array());
        $mform->setDefault('id_matching', $id_matching);
        $mform->addElement('text', 'check_admin', 'check_admin', array());
        $mform->setDefault('check_admin', $check_admin);
        $mform->addElement('html','</div>');    
        
        //$mform->addElement('html', '<input type="submit" value="Save" onclick="return confirm_save_matching_subject();">');
    }
}

//Form manage blackbox survey
class form_matching_bbsurvey_management extends moodleform {
	public function definition() {
		$mform = $this->_form;
        $check_admin = $this->_customdata['check_admin'];
        $str = $this->_customdata['str'];
        //echo "<script>alert('".$str."');</script>";
        //$mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
		$mform->addElement('html','<div id="matching_bbsurvey_table">'.$str.'</div>');
        //div chheck ai dang login, admin or matchmaker
        $mform->addElement('html','<div style="display:none">');    
        $mform->addElement('text', 'check_admin', 'check_admin', array());
        $mform->setDefault('check_admin', $check_admin);
        $mform->addElement('html','</div>'); 
	}
}

//Form input management cho matching
class form_input_management extends moodleform {
    public function definition(){
        $mform = $this->_form;
        $str = $this->_customdata['str'];
        $check_admin = $this->_customdata['check_admin'];
		$mform->addElement('html','<div id="ipm">'.$str.'</div>');
                                
        //div chheck ai dang login, admin or matchmaker
        $mform->addElement('html','<div style="display:none">');    
        $mform->addElement('text', 'check_admin', 'check_admin', array());
        $mform->setDefault('check_admin', $check_admin);
        $mform->addElement('html','</div>');
    }
}

//Form output management cho matching
class form_output_management extends moodleform {
    public function definition(){
        $mform = $this->_form;
        $str = $this->_customdata['str'];
        $check_admin = $this->_customdata['check_admin'];
		$mform->addElement('html','<div id="opm">'.$str.'</div>');
                                
        //div chheck ai dang login, admin or matchmaker
        $mform->addElement('html','<div style="display:none">');    
        $mform->addElement('text', 'check_admin', 'check_admin', array());
        $mform->setDefault('check_admin', $check_admin);
        $mform->addElement('html','</div>');
    }
}


//Form manage matching subject
class form_matching_subject_management extends moodleform {
	public function definition() {
		$mform = $this->_form;
        $str = $this->_customdata['str'];
        $check_admin = $this->_customdata['check_admin'];
		$mform->addElement('html','<div id="matching_subject_table">'.$str.'</div>');
        //div chheck ai dang login, admin or matchmaker
        $mform->addElement('html','<div style="display:none">');    
        $mform->addElement('text', 'check_admin', 'check_admin', array());
        $mform->setDefault('check_admin', $check_admin);
        $mform->addElement('html','</div>');
	}
}
//******************************************************************************************************************************************************************
//                                                                              FORM QUESTIONNAIRE MANAGEMENT
//******************************************************************************************************************************************************************
//form add new input, dung trong do & edit survey
class form_add_new_inout_questionaire extends moodleform{

	public function definition () {
        $mform =& $this->_form;
        
        //lay cac data cua new input
        $id_qn = $this->_customdata['id_qn'];
        $id = $this->_customdata['id'];
        $ip_content = $this->_customdata['content'];
        $action = $this->_customdata['action'];

        //hien noi dung input
		$mform->addElement('htmleditor', 'txtcont', 'Content');
		$mform->setType('txtcont', PARAM_CLEANHTML);
        $mform->addRule('txtcont', 'This field cannot be blanked!', 'required', null, 'client');
        $mform->setDefault('txtcont',$ip_content);
        
        //start hiden div
        $mform->addElement('html','<div id="divSubCheck" style="display: none">');
        
        //luu lai id questionaire, id_input, action
        $mform->addElement('text', 'txtidqn', 'ID questionaire', $attributes='size="40"');
        $mform->setDefault('txtidqn',$id_qn);
        
        $mform->addElement('text', 'txtid', 'ID', $attributes='size="40"');
        $mform->setDefault('txtid',$id);
        //luu lai action
        $mform->addElement('text', 'txtaction', 'action', $attributes='size="40"');
        $mform->setDefault('txtaction',$action);
        //end hidden div
        $mform->addElement('html','</div>');
        
        //submit
		$mform->addElement('submit', 'submitbutton', get_string('savechanges'), array('id'=>'submitbutton','style'=>''));
		$mform->closeHeaderBefore('submitbutton');

	}
}

//Form manage questionaire, dung cho lecturer
class form_questionaire_management extends moodleform {
	public function definition() {
		$mform = $this->_form;
        
        $str = $this->_customdata['str'];
        //echo "<script>alert('".$str."');</script>";
        //$mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
		$mform->addElement('html','<div id="questionaire_table">'.$str.'</div>');
	}
}

//Form do survey, lam pheiu khao sat
class form_do_questionaire extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $new_request = $this->_customdata['new_request'];
        $qn_id = $this->_customdata['questionaire_id'];
		$program = $this->_customdata['program'];
        $id_bb = $this->_customdata['id_bb'];
		$id_sub = $this->_customdata['id_sub'];
        $id_program = $this->_customdata['id_program'];
        $subject = $this->_customdata['subject'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        $n = $this->_customdata['ques_num'];
        $guide_in = $this->_customdata['guide_in'];
        $guide_out = $this->_customdata['guide_out'];
        $print_line = $this->_customdata['print_line'];
        $path_image = $this->_customdata['path_image'];
        
        $table_row = '';
        for($i = 1; $i<=$print_line; $i++){
            $table_row .= '<tr border=1 class="subject" align=center><td>'.$i.'</td><td></td><td></td><td></td><td></td></tr>';
        }

        $table_row1 = '';
        for($i = 1; $i<=$print_line; $i++){
            $table_row1 .= '<tr border=1 class="subject" align=center><td>'.$i.'</td><td></td></tr>';
        }
        
        
        $mform->addElement('html', '<input type="submit" value="'.get_string('save', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(-1,'."'".get_string('savequestionairealert', 'local_blackboxsurvey')."'".');">');
        $mform->addElement('html', '<input type="submit" value="'.get_string('submit', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(1,'."'".get_string('submitquestionairealert', 'local_blackboxsurvey')."'".');">');
        
        //$mform->addElement('html', '<div style="height:500px;width:75%px;border:0px solid #ccc;fontsize:medium Georgia, Garamond, Serif;overflow:auto;">');
                
        //$mform->addElement('html', '<p><div class="headingblock header">'.get_string('basicinformation', 'local_blackboxsurvey').'</div></p>');
        $display_index = 'b_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('basic_info', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">
        <table id="" border=1 style="border:thin solid #DDD;">
		<tr><td class="headingblock header" width=150px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
        <tr><td class="headingblock header" width=150px>'.get_string('subject', 'local_blackboxsurvey').'</td><td>'.$subject.'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('begindate', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('enddate', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table>
        </div>');
        
		//$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('question', 'local_blackboxsurvey').'</div></p>');
        $display_index = 'ques_list';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('question', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        for($i=1;$i<=$n;$i++){
            $q = $this->_customdata['ques_content'.$i];
            $mform->addElement('html', '<br/><h5>'.$q.'</h5>');
            
            //save lai id va dang cua tung cau hoi
            $ques_type = $this->_customdata['type'.$i];
            $ques_id = $this->_customdata['ques_id'.$i];
            $ques_id_type .= '<br><input type="checkbox" name="ques_id[]" checked="checked" value="'.$ques_id.'"> '.$ques_id.
                            '<input type="checkbox" name="ques_type[]" checked="checked" value="'.$ques_type.'"> '.$ques_type;
                            
            //hi?n khung tra l?i cau h?i
            if($ques_type == 1){
                $mform->addElement('html', '<br><textarea name="ques_ans'.$i.'" cols="30" rows="5" style="width: 277px; height: 101px; margin-left:35px;"></textarea><br/>'); 
            }
            //multichoice question - many answer - checkbox
            elseif($ques_type == 2){
                $m = $this->_customdata['num_choice'.$i];
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $mform->addElement('html', '<br><input type="checkbox" style="margin-left:35px;" name="ques_ans'.$i.'[]" value="'.$opt_id.'"> '.$opt_content.'<br>');
                }
            }
            //multichoice question - single answer - radio
            elseif ($ques_type == 3){
                $m = $this->_customdata['num_choice'.$i];
                $radioarray=array();
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $mform->addElement('html', '<br><input type="radio" style="margin-left:35px;" name="ques_ans'.$i.'" value="'.$opt_id.'"> '.$opt_content.'<br>'); 
                }
                $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
            }
            //hien yes no question
            elseif ($ques_type == 4){
                $mform->addElement('html', '<select name="ques_ans'.$i.'">
                                            <option value="0">'.get_string('noq', 'local_blackboxsurvey').'</option>
                                            <option value="1">'.get_string('yesq', 'local_blackboxsurvey').'</option>
                                            </select>'); 
            }
            $mform->addElement('html', '<br/>');
        }
        $mform->addElement('html', '</div>');
        
        $display_index = 'input_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('inputinformation', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        //$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('inputinformation', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<p><h5>'.get_string('listofprerequisitesubject', 'local_blackboxsurvey').'</h5></p>');
        
        //<a class="insub_inline" onClick="load_insub_do_questionaire('.$id_program.');" href="#insubtable" > (Add) </a>
        $mform->addElement('html', '<table id="tb_selected_insub" border="1" style="border:thin solid #DDD;">
    		<th class="headingblock header" width=50px>'.get_string('no', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=450px>'.get_string('subject', 'local_blackboxsurvey').'</th>'.$table_row1.'</table>');
          
        $mform->addElement('html', '<p><h5>'.get_string('listofprerequisiteknowledgeskillsandattitudes', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide4input', 'local_blackboxsurvey').'<br>'.$guide_in.'</i></p>');
        
        
        $mform->addElement('html', '<table id="selected_inlo" border=1 style="border:thin solid #DDD;">
    		<th class="headingblock header" width=50px>'.get_string('remove', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=400px>'.get_string('description', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=50px>'.get_string('type', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=350px>'.get_string('prerequisitesubject', 'local_blackboxsurvey').'</th>'
    		/*.'<th class="headingblock header" width=100px>Learning Outcome</th>'.$table_row*/.'</table>');
        $mform->addElement('html', '<h3>
                <a align="left" onClick="add_edit_new_input_questionaire_colorbox('.$qn_id.',0,'."'add'".');" >'.get_string('newq', 'local_blackboxsurvey').'</a>'
                ./*'<a align="left" onClick="load_inlo_add_questionaire_colorbox('.$qn_id.','.$id_program.');" >[Load]</a>'*/
            '</h3>');
        $mform->addElement('html', '</div>');
        
        
        //$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('outputinformation', 'local_blackboxsurvey').'<font id="request_mess" style="color:red;"> '.$new_request.'</font></div></p>');
        $display_index = 'output_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('outputinformation', 'local_blackboxsurvey').'<font id="request_mess" style="color:red;"> '.$new_request.'</font>
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        $mform->addElement('html', '<p><h5>'.get_string('listofsubjectwilluseknowledgeandskillsofthissubject', 'local_blackboxsurvey').'</h5></p>');
        
        //<a class="outsub_inline" onClick="load_outsub_do_questionaire('.$id_program.');" href="#outsubtable" > (Add) </a>
        $mform->addElement('html', '<table id="tb_selected_outsub" border=1 style="border:thin solid #DDD;">
            <th class="headingblock header" width=50px>'.get_string('remove', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=450px>'.get_string('subject', 'local_blackboxsurvey').'</th>'.$table_row1.'
            </table>');
            
        $mform->addElement('html', '<p><h5>'.get_string('listofknowledgeskillsandattitudeswillbegainedafterthissubject', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide4output', 'local_blackboxsurvey').'<br>'.$guide_out.'</i></p>');
        
        $mform->addElement('html', '<table id="selected_outlo" border=1 style="border:thin solid #DDD;">
    		<th class="headingblock header" width=50px>'.get_string('remove', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=400px>'.get_string('description', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=50px>'.get_string('type', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('use4subject', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=100px>'.get_string('learningoutcome', 'local_blackboxsurvey').'</th>'.$table_row.'</table>');
        
        $mform->addElement('html', '<h3>
                <a align="left" onClick="add_edit_new_output_questionaire_colorbox('.$qn_id.',0,'."'add'".');" >'.get_string('newq', 'local_blackboxsurvey').'</a>
                <a align="left" onClick="load_outlo_add_questionaire_colorbox('.$qn_id.','.$id_program.');" >'.get_string('loadfromsyllabus', 'local_blackboxsurvey').'</a>
                <a align="left" onClick="load_request_add_questionaire_colorbox('.$qn_id.');" >'.get_string('loadfromrequest', 'local_blackboxsurvey').'</a>
            </h3>');
      $mform->addElement('html', '</div>');
      
      $mform->addElement('html', '<input type="submit" value="'.get_string('save', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(-1,'."'".get_string('savequestionairealert', 'local_blackboxsurvey')."'".');">');
      $mform->addElement('html', '<input type="submit" value="'.get_string('submit', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(1,'."'".get_string('submitquestionairealert', 'local_blackboxsurvey')."'".');">');

      
      //div an chua du lieu
      $mform->addElement('html','<div style="display:none">');        
            //danh sach id va type cua questions
            $mform->addElement('html', $ques_id_type);
            //id cua phieu khao sat
            $mform->addElement('text', 'qn_id', 'questionaire_id', array());
            $mform->setDefault('qn_id', $qn_id);
            //action save or submit
            $mform->addElement('text', 'txt_action', 'action', array());
      $mform->addElement('html','</div>');
      //$mform->addElement('html','</div>');
    }
}
//Form view
class form_view_questionaire extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $qn_id = $this->_customdata['questionaire_id'];
		$program = $this->_customdata['program'];
        $id_program = $this->_customdata['id_program'];
        $subject = $this->_customdata['subject'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        $n = $this->_customdata['ques_num'];
        $guide_in = $this->_customdata['guide_in'];
        $guide_out = $this->_customdata['guide_out'];
        $print_line = $this->_customdata['print_line'];
        $view_in = $this->_customdata['view_in'];
        $view_out = $this->_customdata['view_out'];
        $view_psi = $this->_customdata['view_psi'];
        $view_pso = $this->_customdata['view_pso'];
        $path_image = $this->_customdata['path_image'];
        
        //$mform->addElement('html', '<input type="submit" value="Save" onclick="set_action_questionaire(-1);">');
        //$mform->addElement('html', '<input type="submit" value="Submit" onclick="set_action_questionaire(1);">');
        $display_index = 'b_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('basic_info', 'local_blackboxsurvey').'
                                    </div></p>');
        //$mform->addElement('html', '<p><div class="headingblock header">'.get_string('basicinformation', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">
        <table id="" border=0>
		<tr><td class="headingblock header" width=150px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
        <tr><td class="headingblock header" width=150px>'.get_string('subject', 'local_blackboxsurvey').'</td><td>'.$subject.'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('begindate', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('enddate', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table>
        </div>');
        
        $display_index = 'ques_list';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('question', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        //$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('question', 'local_blackboxsurvey').'</div></p>');
        for($i=1;$i<=$n;$i++){
            $q = $this->_customdata['ques_content'.$i];
            $mform->addElement('html', '<br/><h5>'.$q.'</h5>');
            
            //save lai id va dang cua tung cau hoi
            $ques_type = $this->_customdata['type'.$i];
            $ques_id = $this->_customdata['ques_id'.$i];
            $ques_id_type .= '<br><input type="checkbox" name="ques_id[]" checked="checked" value="'.$ques_id.'"> '.$ques_id.
                            '<input type="checkbox" name="ques_type[]" checked="checked" value="'.$ques_type.'"> '.$ques_type;
                            
            //hi?n khung tra l?i cau h?i
            if($ques_type == 1){
                $ans = $this->_customdata['ans'.$i];
                $mform->addElement('html', '<br/><textarea name="ques_ans'.$i.'" cols="30" rows="5" style="width: 277px; height: 101px; margin-left:35px">'.$ans.'</textarea><br/>'); 
            }
            //multichoice question - many answer - checkbox
            elseif($ques_type == 2){
                $m = $this->_customdata['num_choice'.$i];
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $checked = $this->_customdata['choice_ck'.$i.$j];
                    $mform->addElement('html', '<br><input type="checkbox" style="margin-left:35px;" '.$checked.' name="ques_ans'.$i.'[]" value="'.$opt_id.'"> '.$opt_content.'<br>');
                }
            }
            //multichoice question - single answer - radio
            elseif ($ques_type == 3){
                $m = $this->_customdata['num_choice'.$i];
                $radioarray=array();
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $checked = $this->_customdata['choice_ck'.$i.$j];
                    $mform->addElement('html', '<br><input type="radio" style="margin-left:35px;" '.$checked.' name="ques_ans'.$i.'" value="'.$opt_id.'"> '.$opt_content.'<br>'); 
                }
                $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
            }
            //hien yes no question
            elseif ($ques_type == 4){
                $ans = $this->_customdata['ans'.$i];
                if($ans == 0)
                    $select0 = 'selected';
                elseif($ans == 1)
                    $select1 = 'selected';
                $mform->addElement('html', '<select name="ques_ans'.$i.'">
                                            <option '.$select0.' value="0">'.get_string('noq', 'local_blackboxsurvey').'</option>
                                            <option '.$select1.' value="1">'.get_string('yesq', 'local_blackboxsurvey').'</option>
                                            </select>'); 
            }
            $mform->addElement('html', '<br/>');
        }
        $mform->addElement('html', '</div>');
        
        $display_index = 'input_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('inputinformation', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        //$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('inputinformation', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<p><h5>'.get_string('listofprerequisitesubject', 'local_blackboxsurvey').'</h5></p>');
        
        //<a class="insub_inline" onClick="load_insub_do_questionaire('.$id_program.');" href="#insubtable" > (Add) </a>
        $mform->addElement('html', '<table id="tb_selected_insub" border="1">'.$view_psi.'</table>');
          
        $mform->addElement('html', '<p><h5>'.get_string('listofprerequisiteknowledgeskillsandattitudes', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide4input', 'local_blackboxsurvey').'<br>'.$guide_in.'</i></p>');
        
        /*$mform->addElement('html', '<h3>
                <a align="left" onClick="add_edit_new_input_questionaire_colorbox('.$qn_id.',0,'."'add'".');" >[New]</a>
                <a align="left" onClick="load_inlo_add_questionaire_colorbox('.$qn_id.','.$id_program.');" >[Load]</a>
            </h3>');*/
        $mform->addElement('html', '<table id="selected_inlo" border=1>'.$view_in.'</table>');
        $mform->addElement('html', '</div>');
            
        $display_index = 'output_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('outputinformation', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        //$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('outputinformation', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<p><h5>'.get_string('listofsubjectwilluseknowledgeandskillsofthissubject', 'local_blackboxsurvey').'</h5></p>');
        
        //<a class="outsub_inline" onClick="load_outsub_do_questionaire('.$id_program.');" href="#outsubtable" > (Add) </a>
        $mform->addElement('html', '<table id="tb_selected_outsub" border=1>'.$view_pso.'
            </table>');
            
        $mform->addElement('html', '<p><h5>'.get_string('listofknowledgeskillsandattitudeswillbegainedafterthissubject', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide4output', 'local_blackboxsurvey').'<br>'.$guide_out.'</i></p>');
        
        $mform->addElement('html', '<table id="selected_outlo" border=1>'.$view_out.'</table>');
        $mform->addElement('html', '</div>');
      //div an chua du lieu
      $mform->addElement('html','<div style="display:none">');        
            //danh sach id va type cua questions
            $mform->addElement('html', $ques_id_type);
            //id cua phieu khao sat
            $mform->addElement('text', 'qn_id', 'questionaire_id', array());
            $mform->setDefault('qn_id', $qn_id);
            //action save or submit
            $mform->addElement('text', 'txt_action', 'action', array());
      $mform->addElement('html','</div>');   
    }
}
//Form edit
class form_edit_questionaire extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $new_request = $this->_customdata['new_request'];
        $qn_id = $this->_customdata['questionaire_id'];
		$program = $this->_customdata['program'];
        $id_program = $this->_customdata['id_program'];
        $subject = $this->_customdata['subject'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        $n = $this->_customdata['ques_num'];
        $guide_in = $this->_customdata['guide_in'];
        $guide_out = $this->_customdata['guide_out'];
        $print_line = $this->_customdata['print_line'];
        $view_in = $this->_customdata['view_in'];
        $view_out = $this->_customdata['view_out'];
        $view_psi = $this->_customdata['view_psi'];
        $view_pso = $this->_customdata['view_pso'];
        $path_image = $this->_customdata['path_image'];
        
        $mform->addElement('html', '<input type="submit" value="'.get_string('save', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(-1,'."'".get_string('savequestionairealert', 'local_blackboxsurvey')."'".');">');
        $mform->addElement('html', '<input type="submit" value="'.get_string('submit', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(1,'."'".get_string('submitquestionairealert', 'local_blackboxsurvey')."'".');">');
        
        //$mform->addElement('html', '<p><div class="headingblock header">'.get_string('basicinformation', 'local_blackboxsurvey').'</div></p>');
        $display_index = 'b_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('basic_info', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">
        <table id="" border=0>
		<tr><td class="headingblock header" width=150px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
        <tr><td class="headingblock header" width=150px>'.get_string('subject', 'local_blackboxsurvey').'</td><td>'.$subject.'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('begindate', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('enddate', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table></div>');
        
		//$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('question', 'local_blackboxsurvey').'</div></p>');
        $display_index = 'question_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('question', 'local_blackboxsurvey').'
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        for($i=1;$i<=$n;$i++){
            $q = $this->_customdata['ques_content'.$i];
            $mform->addElement('html', '<br/><h5>'.$q.'</h5>');
            
            //save lai id va dang cua tung cau hoi
            $ques_type = $this->_customdata['type'.$i];
            $ques_id = $this->_customdata['ques_id'.$i];
            $ques_id_type .= '<br><input type="checkbox" name="ques_id[]" checked="checked" value="'.$ques_id.'"> '.$ques_id.
                            '<input type="checkbox" name="ques_type[]" checked="checked" value="'.$ques_type.'"> '.$ques_type;
                            
            //hi?n khung tra l?i cau h?i
            if($ques_type == 1){
                $ans = $this->_customdata['ans'.$i];
                $mform->addElement('html', '<textarea name="ques_ans'.$i.'" cols="30" rows="5" style="width: 277px; height: 101px; margin-left:35px;">'.$ans.'</textarea><br/>'); 
            }
            //multichoice question - many answer - checkbox
            elseif($ques_type == 2){
                $m = $this->_customdata['num_choice'.$i];
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $checked = $this->_customdata['choice_ck'.$i.$j];
                    $mform->addElement('html', '<input type="checkbox" style="margin-left:35px;" '.$checked.' name="ques_ans'.$i.'[]" value="'.$opt_id.'"> '.$opt_content.'<br>');
                }
            }
            //multichoice question - single answer - radio
            elseif ($ques_type == 3){
                $m = $this->_customdata['num_choice'.$i];
                $radioarray=array();
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $checked = $this->_customdata['choice_ck'.$i.$j];
                    $mform->addElement('html', '<input type="radio" style="margin-left:35px;" '.$checked.' name="ques_ans'.$i.'" value="'.$opt_id.'"> '.$opt_content.'<br>'); 
                }
                $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
            }
            //hien yes no question
            elseif ($ques_type == 4){
                $ans = $this->_customdata['ans'.$i];
                if($ans == 0)
                    $select0 = 'selected';
                elseif($ans == 1)
                    $select1 = 'selected';
                $mform->addElement('html', '<select name="ques_ans'.$i.'">
                                            <option '.$select0.' value="0">'.get_string('noq', 'local_blackboxsurvey').'</option>
                                            <option '.$select1.' value="1">'.get_string('yesq', 'local_blackboxsurvey').'</option>
                                            </select>'); 
            }
            $mform->addElement('html', '<br/>');
        }
        $mform->addElement('html', '</div>');
        
        
        //$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('inputinformation', 'local_blackboxsurvey').'</div></p>');
        $display_index = 'input_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('inputinformation', 'local_blackboxsurvey').'
                                        </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        $mform->addElement('html', '<p>'.get_string('listofprerequisitesubject', 'local_blackboxsurvey').'</p>');
        
        //<a class="insub_inline" onClick="load_insub_do_questionaire('.$id_program.');" href="#insubtable" > (Add) </a>
        $mform->addElement('html', '<div id="tb_selected_insub" border="1">'.$view_psi.'</div>');
          
        $mform->addElement('html', '<p>'.get_string('listofprerequisiteknowledgeskillsandattitudes', 'local_blackboxsurvey').'</p>');
        $mform->addElement('html', '<p><i>'.get_string('guide4input', 'local_blackboxsurvey').'<br>'.$guide_in.'</i></p>');
        
        $mform->addElement('html', '<div id="selected_inlo" border=1>'.$view_in.'</div>');
        $mform->addElement('html', '<h3>
                <a align="left" onClick="add_edit_new_input_questionaire_colorbox('.$qn_id.',0,'."'add'".');" >'.get_string('newq', 'local_blackboxsurvey').'</a>'.
                /*'<a align="left" onClick="load_inlo_add_questionaire_colorbox('.$qn_id.','.$id_program.');" >[Load]</a>'.*/
            '</h3>');
        $mform->addElement('html', '</div>');
        
        
        //$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('outputinformation', 'local_blackboxsurvey').'<font id="request_mess" style="color:red;"> '.$new_request.'</font></div></p>');
        $display_index = 'output_info';
        $mform->addElement('html', '<p><div class="headingblock header">
                                        <img id="show'.$display_index.'" style="cursor:pointer;display:none;" class="icon" src="'.$path_image.'show.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        <img id="hide'.$display_index.'" style="cursor:pointer;" class="icon" src="'.$path_image.'hide.jpg" onclick="show_hide_answer_content('."'".$display_index."'".');"/>
                                        '.get_string('outputinformation', 'local_blackboxsurvey').'<font id="request_mess" style="color:red;"> '.$new_request.'</font>
                                    </div></p>');
        $mform->addElement('html', '<div id="display_content'.$display_index.'" style="cursor:pointer;">');
        $mform->addElement('html', '<p>'.get_string('listofsubjectwilluseknowledgeandskillsofthissubject', 'local_blackboxsurvey').'</p>');
        
        //<a class="outsub_inline" onClick="load_outsub_do_questionaire('.$id_program.');" href="#outsubtable" > (Add) </a>
        $mform->addElement('html', '<div id="tb_selected_outsub" border=1>'.$view_pso.'</div>');
            
        $mform->addElement('html', '<p>'.get_string('listofknowledgeskillsandattitudeswillbegainedafterthissubject', 'local_blackboxsurvey').'</p>');
        $mform->addElement('html', '<p><i>'.get_string('guide4output', 'local_blackboxsurvey').'<br>'.$guide_out.'</i></p>');
        
        $mform->addElement('html', '<div id="selected_outlo" border=1>'.$view_out.'</div>');
        $mform->addElement('html', '<h3>
                <a align="left" onClick="add_edit_new_output_questionaire_colorbox('.$qn_id.',0,'."'add'".');" >'.get_string('newq', 'local_blackboxsurvey').'</a>
                <a align="left" onClick="load_outlo_add_questionaire_colorbox('.$qn_id.','.$id_program.');" >'.get_string('loadfromsyllabus', 'local_blackboxsurvey').'</a>
                <a align="left" onClick="load_request_add_questionaire_colorbox('.$qn_id.');" >'.get_string('loadfromrequest', 'local_blackboxsurvey').'</a>
            </h3>');
      $mform->addElement('html', '</div>');
      
      $mform->addElement('html', '<input type="submit" value="'.get_string('save', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(-1,'."'".get_string('savequestionairealert', 'local_blackboxsurvey')."'".');">');
      $mform->addElement('html', '<input type="submit" value="'.get_string('submit', 'local_blackboxsurvey').'" onclick="return set_action_questionaire(1,'."'".get_string('submitquestionairealert', 'local_blackboxsurvey')."'".');">');
      
            
      //div an chua du lieu
      $mform->addElement('html','<div style="display:none">');        
            //danh sach id va type cua questions
            $mform->addElement('html', $ques_id_type);
            //id cua phieu khao sat
            $mform->addElement('text', 'qn_id', 'questionaire_id', array());
            $mform->setDefault('qn_id', $qn_id);
            //action save or submit
            $mform->addElement('text', 'txt_action', 'action', array());
      $mform->addElement('html','</div>');   
    }
}
//*******************************************************************************************************************************************************************
//                                                                                 FORM CUA ADMIN
//*******************************************************************************************************************************************************************

//Form cua Admin
class form_AdminInterface extends moodleform {
	public function definition() {
		$mform = $this->_form;
        $str = $this->_customdata['str'];
        //echo "<script>alert('".$str."');</script>";
        $mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
		$mform->addElement('html','<div id="survey_able">'.$str.'</div>');
	}
}

//Form print review
class form_print_survey extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $id = $this->_customdata['id'];
		$program = $this->_customdata['program'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        $n = $this->_customdata['ques_num'];
        $guide_in = $this->_customdata['guide_in'];
        $guide_out = $this->_customdata['guide_out'];
        $print_line = $this->_customdata['print_line'];
        
        $table_row = '';
        for($i = 1; $i<=$print_line; $i++){
            $table_row .= '<tr border=1 class="subject" align=center><td>'.$i.'</td><td></td><td></td><td></td><td></td></tr>';
        }

        $table_row1 = '';
        for($i = 1; $i<=$print_line; $i++){
            $table_row1 .= '<tr border=1 class="subject" align=center><td>'.$i.'</td><td></td></tr>';
        }
        
        $mform->addElement('html', '<p><div class="headingblock header" style="width: 950px;">Basic Information</div></p>');
        $mform->addElement('html', '<table id="" border=0>
		<tr><td class="headingblock headerprint" width=100px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
		<tr><td class="headingblock headerprint" width=100px>'.get_string('publish_date', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
		<tr><td class="headingblock headerprint" width=100px>'.get_string('end_date', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table>');
        
		$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;width: 950px;">Question</div></p>');
        for($i=1;$i<=$n;$i++){
            $q = $this->_customdata['ques_content'.$i];
            $mform->addElement('html', '<h5>'.$q.'</h5>');
            
            $ques_type = $this->_customdata['type'.$i];
            
            //hi?n khung tra l?i cau h?i
            if($ques_type == 1){
                $mform->addElement('<div style="margin-right:5000px">');
                //$mform->addElement('textarea', 'opt_cache', '', 'rows="5" cols="30"');
                $mform->addElement('html', '<textarea cols="30" rows="5" style="width: 277px; height: 101px;"></textarea><br/>');
                $mform->addElement('</div>');                 
            }
            //multichoice question - many answer - checkbox
            elseif($ques_type == 2){
                $m = $this->_customdata['num_choice'.$i];
                $mform->addElement('<div style="margin-right:5000px">');
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $mform->addElement('advcheckbox', 'opt'.$i.$j, '', $opt_content, array('group' => 1),  $opt_id);
                }
                $mform->addElement('</div>');
            }
            //multichoice question - single answer - radio
            elseif ($ques_type == 3){
                $m = $this->_customdata['num_choice'.$i];
                $radioarray=array();
                $mform->addElement('<div style="margin-right:5000px">');
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $radioarray[] = $mform->createElement('radio', 'opt', '', $opt_content, $opt_id, $attributes);
                }
                $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
                $mform->addElement('</div>');
            }
            //hien yes no question
            elseif ($ques_type == 4){
                $mform->addElement('selectyesno', 'maxbytes');
            }
        }
        
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;width: 950px;">'.get_string('input_info', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<p><h5>'.get_string('presubjectlist1', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<table id="" border=1>
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=890px>'.get_string('subject', 'local_blackboxsurvey').'</th>'.$table_row1.'</table>');
            
        $mform->addElement('html', '<p><h5>'.get_string('prelist2', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide_in', 'local_blackboxsurvey').'<br>'.$guide_in.'</i></p>');
        $mform->addElement('html', '<table id="" border=1>
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('description', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=100px>'.get_string('type', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('pre_subject', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=250px>'.get_string('learning_outcome', 'local_blackboxsurvey').'</th>'.$table_row.'</table>');
        
            
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;width: 950px;">'.get_string('output_info', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<p><h5>'.get_string('subjectuselist1', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<table id="" border=1>
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=890px>'.get_string('subject', 'local_blackboxsurvey').'</th>'.$table_row1.'</table>');
        $mform->addElement('html', '<p><h5>'.get_string('gainedlist2', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide_out', 'local_blackboxsurvey').'<br>'.$guide_out.'</i></p>');
        $mform->addElement('html', '<table id="" border=1>
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('description', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=100px>'.get_string('type', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('usedfor_subject', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=250px>'.get_string('learning_outcome', 'local_blackboxsurvey').'</th>'.$table_row.'</table>');
    }
}

//Form survey review
class form_review_survey extends moodleform {
	public function definition() {
		global $DB;
		$mform = $this->_form;
        $id = $this->_customdata['id'];
		$program = $this->_customdata['program'];
        $start = $this->_customdata['start'];
		$end = $this->_customdata['end'];
        $n = $this->_customdata['ques_num'];
        $guide_in = $this->_customdata['guide_in'];
        $guide_out = $this->_customdata['guide_out'];
        $print_line = $this->_customdata['print_line'];
        
        $table_row = '';
        for($i = 1; $i<=$print_line; $i++){
            $table_row .= '<tr border=1 class="subject" align=center style="border:thin solid #DDD;"><td>'.$i.'</td><td></td><td></td><td></td><td></td></tr>';
        }

        $table_row1 = '';
        for($i = 1; $i<=$print_line; $i++){
            $table_row1 .= '<tr border=1 class="subject" align=center style="border:thin solid #DDD;"><td>'.$i.'</td><td></td></tr>';
        }
        
        $mform->addElement('html', '<a href="print.php?id='.$id.'">'.get_string('print_version', 'local_blackboxsurvey').'</a>');
                
//        $mform->addElement('text', '', '', array('style'=>'display: none'));
        $mform->addElement('html', '<p><div class="headingblock header">'.get_string('basic_info1', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<table id="" border=0>
		<tr><td class="headingblock header" width=150px>'.get_string('program', 'local_blackboxsurvey').'</td><td>'.$program.'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('publish_date', 'local_blackboxsurvey').'</td><td>'.userdate($start).'</td></tr>
		<tr><td class="headingblock header" width=150px>'.get_string('end_date', 'local_blackboxsurvey').'</td><td>'.userdate($end).'</td></tr></table>');
        
		$mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('question', 'local_blackboxsurvey').'</div></p>');
        for($i=1;$i<=$n;$i++){
            $q = $this->_customdata['ques_content'.$i];
            $mform->addElement('html', '<h5>'.$q.'</h5>');
            
            $ques_type = $this->_customdata['type'.$i];
            
            //hi?n khung tra l?i cau h?i
            if($ques_type == 1){
                //$mform->addElement('html', '<textarea cols="30" rows="5" style="width: 277px; height: 101px;"></textarea><br/>');
                $mform->addElement('textarea', 'opt_cache', '', 'rows="5" cols="30"');
            }
            //multichoice question - many answer - checkbox
            elseif($ques_type == 2){
                $m = $this->_customdata['num_choice'.$i];
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $mform->addElement('advcheckbox', 'opt'.$i.$j, '', "  ".$opt_content, array('group' => 1),  $opt_id);
                }
            }
            //multichoice question - single answer - radio
            elseif ($ques_type == 3){
                $m = $this->_customdata['num_choice'.$i];
                $radioarray=array();
                for($j = 1;$j<=$m;$j++)
                {
                    $opt_id = $this->_customdata['choice_id'.$i.$j];
                    $opt_content = $this->_customdata['choice_content'.$i.$j];
                    $radioarray[] = $mform->createElement('radio', 'opt', '', "  ".$opt_content, $opt_id, $attributes);
                }
                $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
            }
            //hien yes no question
            elseif ($ques_type == 4){
                $mform->addElement('selectyesno', 'maxbytes');
            }
        }
        
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('input_info', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<p><h5>'.get_string('subjectuselist1', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<table id="" border=0 style="border:thin solid #DDD;">
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=450px>'.get_string('subject', 'local_blackboxsurvey').'</th>'.$table_row1.'</table>');
            
        $mform->addElement('html', '<p><h5>'.get_string('gainedlist2', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide_in', 'local_blackboxsurvey').'<br>'.$guide_in.'</i></p>');
        $mform->addElement('html', '<table id="" border=0 style="border:thin solid #DDD;">
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('description', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=50px>'.get_string('type', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('pre_subject', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=250px>'.get_string('learning_outcome', 'local_blackboxsurvey').'</th>'.$table_row.'</table>');
        
            
        $mform->addElement('html', '<p><div class="headingblock header" style="margin-top: 10px;">'.get_string('output_info', 'local_blackboxsurvey').'</div></p>');
        $mform->addElement('html', '<p><h5>'.get_string('subjectuselist1', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<table id="" border=0 style="border:thin solid #DDD;">
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=450px>'.get_string('subject', 'local_blackboxsurvey').'</th>'.$table_row1.'</table>');
        $mform->addElement('html', '<p><h5>'.get_string('gainedlist2', 'local_blackboxsurvey').'</h5></p>');
        $mform->addElement('html', '<p><i>'.get_string('guide_out', 'local_blackboxsurvey').'<br>'.$guide_out.'</i></p>');
        $mform->addElement('html', '<table id="" border=0 style="border:thin solid #DDD;">
    		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('description', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=50px>'.get_string('type', 'local_blackboxsurvey').'</th>
            <th class="headingblock header" width=250px>'.get_string('usedfor_subject', 'local_blackboxsurvey').'</th>
    		<th class="headingblock header" width=250px>'.get_string('learning_outcome', 'local_blackboxsurvey').'</th>'.$table_row.'</table>');
    }
}

//Form survey detail (statictics cua cuoc khoa sat ve giao vien)
class form_survey_detail extends moodleform {
	public function definition() {
		$mform = $this->_form;
        $program = $this->_customdata['program'];
        $str = $this->_customdata['str'];
        //echo "<script>alert('".$str."');</script>";
        //$mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
        $mform->addElement('html', '<h1>'.get_string('program', 'local_blackboxsurvey').': '.$program.'</h1>');
		$mform->addElement('html','<div id="lecturertable">'.$str.'</div>');
	}
}

//Form tao survey
class form_create_survey extends moodleform {
	public function definition() {
	
        global $DB;
		$mform = $this->_form;
        $survey_id = $this->_customdata['survey_id'];
        $guide_input = $this->_customdata['guide_input'];
        $guide_output = $this->_customdata['guide_output'];
        $id_guide_input = $this->_customdata['id_guide_input'];
        $id_guide_output = $this->_customdata['id_guide_output'];
        //div hien thong bao
        $mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
        
		$mform->addElement('html', '<h1>'.get_string('title_createsurvey', 'local_blackboxsurvey').'</h1>');
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">'.get_string('basic_info1', 'local_blackboxsurvey').'</div>');
        
        //chuong trinh dc tao survey
		//$programs = $DB->get_records('program');
        $sql = 'SELECT * FROM mdl_program a WHERE NOT EXISTS( SELECT null FROM mdl_b_blackbox_survey b WHERE a.id = b.id_program and b.status >= 0)';
        $programs = $DB->get_records_sql($sql);
        $options = array(''=>get_string('choose_program', 'local_blackboxsurvey'));
		foreach($programs as $program) {
			$options[$program->id] = $program->program_name.' - '.$program->program_type;
		}
		$mform->addElement('select', 'program', get_string('available_program', 'local_blackboxsurvey'), $options, array('id'=>'program','onChange'=>''));
        $mform->addRule('program', get_string('blank1', 'local_blackboxsurvey'), 'required', null, 'client');
        //begin date
        $mform->addElement('date_time_selector', 'assesstimestart', get_string('publish_date', 'local_blackboxsurvey'));
        
        //End Date
        $mform->addElement('date_time_selector', 'assesstimefinish', get_string('end_date', 'local_blackboxsurvey'));
        
        //so dòng de dien input output
        $mform->addElement('text', 'lineio', get_string('line', 'local_blackboxsurvey'), array('onkeypress'=>'return keypress(event);'));
        $mform->addRule('lineio', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;"><a class="inline" onClick="load_matcher_add_survey('.$survey_id.');" href="#matchertable" >'.get_string('choose_matchmaker', 'local_blackboxsurvey').'</a></div>'); 
        //Colorbox hien thi assigned matchmaker
		echo '<script>
			$(document).ready(function()
			{
				$(".inline").colorbox(
				{
					inline:true, 
					width:"700px", 
					height:"600px"
                });
			});
		</script>';
        //div an dung de hien colorbox
		$mform->addElement('html','<div style="display:none"><div id="matchertable"></div></div>');
        //$mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">Matchmaker<a onClick="load_matcher_add_survey();" >(Assign Matchmaker)</a></div>');
               
        //div hien thi nhung matchmaker da assign
		$mform->addElement('html', '<div id="selected_matcher">');
		$mform->addElement('html', '<table id="tb_selected_matcher" border=1; style="border:thin solid #DDD;">
		<th class="headingblock header" width=400px>'.get_string('name_matchmaker', 'local_blackboxsurvey').'</th>
		<th class="headingblock header" width=50px>'.get_string('remove', 'local_blackboxsurvey').'</th>
		</table>');
		$mform->addElement('html','</div>');
        
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;"><a onClick="load_question_add_survey_colorbox();" >'.get_string('select_question', 'local_blackboxsurvey').'</a></div>');
		//div hien thi nhung question da chon
		$mform->addElement('html', '<div id="selected_question">');
		$mform->addElement('html', '<table id="tb_selected_question" border=1 style="border:thin solid #DDD;">
		<th class="headingblock header" width=50px>'.get_string('num', 'local_blackboxsurvey').'</th>
		<th class="headingblock header" width=450px>'.get_string('question', 'local_blackboxsurvey').'</th>
		<th class="headingblock header" width=150px>'.get_string('question_type', 'local_blackboxsurvey').'</th>
		<th class="headingblock header" width=50px>'.get_string('remove', 'local_blackboxsurvey').'</th>
		</table>');
		$mform->addElement('html','</div>');
		  
        //guideline input
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">'.get_string('guide_in', 'local_blackboxsurvey').'</div>');
		$mform->addElement('htmleditor', 'txtin', get_string('guidein_content', 'local_blackboxsurvey'));
		$mform->setType('txtin', PARAM_CLEANHTML);
		$mform->addRule('txtin', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        $mform->setDefault('txtin',$guide_input);
		
        //guideline output
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">'.get_string('guide_out', 'local_blackboxsurvey').'</div>');
		$mform->addElement('htmleditor', 'txtout', get_string('guideout_content', 'local_blackboxsurvey'));
		$mform->setType('txtout', PARAM_CLEANHTML);
		$mform->addRule('txtout',get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        $mform->setDefault('txtout',$guide_output);
        
        //div an luu du lieu tam
        $mform->addElement('html','<div style="display: none">');
            $mform->addElement('date_time_selector', 'assesstimecreate', 'Create date');
            $mform->addElement('text', 'txtid', 'ID_survey', $attributes);
            $mform->setDefault('txtid',$survey_id);
            $mform->addElement('text', 'txtid_g_in', 'ID_guide_in', $attributes);
            $mform->setDefault('txtid_g_in',$id_guide_input);
            $mform->addElement('text', 'txtid_g_out', 'ID_guide_out', $attributes);
            $mform->setDefault('txtid_g_out',$id_guide_output);
        $mform->addElement('html','</div>');
        
        //submit button
		$mform->addElement('submit', 'submitbutton', get_string('create_survey1', 'local_blackboxsurvey'), array('id'=>'submitbutton','style'));
		$mform->closeHeaderBefore('submitbutton');                                                                                                       
	}
}

//form edit survey
class form_edit_survey extends moodleform {
	public function definition() {
	
        global $DB;
		$mform = $this->_form;
        $survey_id = $this->_customdata['survey_id'];
        $guide_input = $this->_customdata['guide_input'];
        $guide_output = $this->_customdata['guide_output'];
        $id_guide_input = $this->_customdata['id_guide_input'];
        $id_guide_output = $this->_customdata['id_guide_output'];
        $program_id = $this->_customdata['program_id'];
        $date_start = $this->_customdata['date_start'];
        $date_end = $this->_customdata['date_end'];
        $lineio = $this->_customdata['line_in_out'];
        $survey_ques_str = $this->_customdata['survey_ques_str'];
        $ques_selected = $this->_customdata['ques_selected'];
        $selected_matcher = $this->_customdata['selected_matcher'];
        $matcher_table = $this->_customdata['matcher_table'];
        //div hien thong bao
        $mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
        
		$mform->addElement('html', '<h1>'.get_string('edit_bbsurvey', 'local_blackboxsurvey').'</h1>');
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">'.get_string('basic_info1', 'local_blackboxsurvey').'</div>');
        
        //chuong trinh dc tao survey
		//$programs = $DB->get_records('program');
        //$sql = 'SELECT * FROM mdl_program a WHERE NOT EXISTS( SELECT * FROM mdl_b_blackbox_survey b WHERE a.id = b.id_program and b.status >= 0 and b.id_program != '.$program_id.')';
        //$programs = $DB->get_records_sql($sql);
        $options = array(''=>'Please choose Program');
		/*foreach($programs as $program) {
			$options[$program->id] = $program->program_name.' - '.$program->program_type;
		}*/
        $n_pro = $this->_customdata['n_pro'];
        for($i = 1; $i <= $n_pro; $i++){
            $pro_id = $this->_customdata['pro_id'.$i];
            $pro_vl = $this->_customdata['pro_vl'.$i];
            $options[$pro_id] = $pro_vl;
        }
		$mform->addElement('select', 'program', get_string('choose_program', 'local_blackboxsurvey'), $options, array('id'=>'program','onChange'=>'save_program_id_edit_only(this);'));
        $mform->setDefault('program', $program_id);
        $mform->addRule('program', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        
        //begin date
        $mform->addElement('date_time_selector', 'assesstimestart', get_string('publish_date', 'local_blackboxsurvey'));
        $mform->setDefault('assesstimestart', $date_start);
        
        //End Date
        $mform->addElement('date_time_selector', 'assesstimefinish', get_string('end_date', 'local_blackboxsurvey'));
        $mform->setDefault('assesstimefinish', $date_end);
        
        //so dòng de dien input output
        $mform->addElement('text', 'lineio', get_string('line', 'local_blackboxsurvey'), array('onkeypress'=>'return keypress(event);'));
        $mform->addRule('lineio', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        $mform->setDefault('lineio', $lineio);
        
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;"><a class="inline" onClick="load_matcher_add_survey('.$survey_id.');" href="#matchertable" >'.get_string('choose_matchmaker', 'local_blackboxsurvey').'</a></div>'); 
        //Colorbox hien thi assigned matchmaker
		echo '<script>
			$(document).ready(function()
			{
				$(".inline").colorbox(
				{
					inline:true, 
					width:"600px", 
					height:"600px"
                });
			});
		</script>';
        //div an dung de hien colorbox
		$mform->addElement('html','<div style="display:none"><div id="matchertable">'.$matcher_table.'</div></div>');
        //$mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">Matchmaker<a onClick="load_matcher_add_survey();" >(Assign Matchmaker)</a></div>');
               
        //div hien thi nhung matchmaker
		$mform->addElement('html', '<div id="selected_matcher">'.$selected_matcher.'</div>');
        
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;"><a style="cursor:pointer;" onClick="load_question_add_survey_edit_only_colorbox();">'.get_string('select_question', 'local_blackboxsurvey').'</a></div>');
		
		//div hien thi nhung question da chon
		$mform->addElement('html', '<div id="selected_question">');
		$mform->addElement('html', $survey_ques_str);
		$mform->addElement('html','</div>');
        
		//div an dung de hien colorbox
		//$mform->addElement('html','<div style="display:none"><div id="questiontable"></div></div>');
		  
        //guideline input
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">'.get_string('guide_in', 'local_blackboxsurvey').'</div>');
		$mform->addElement('htmleditor', 'txtin', get_string('guidein_content', 'local_blackboxsurvey'));
		$mform->setType('txtin', PARAM_CLEANHTML);
		$mform->addRule('txtin', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        $mform->setDefault('txtin',$guide_input);
		
        //guideline output
        $mform->addElement('html','<div class="headingblock header" style="margin-top: 10px;">'.get_string('guide_out', 'local_blackboxsurvey').'</div>');
		$mform->addElement('htmleditor', 'txtout', get_string('guideout_content', 'local_blackboxsurvey'));
		$mform->setType('txtout', PARAM_CLEANHTML);
		$mform->addRule('txtout', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        $mform->setDefault('txtout',$guide_output);
        
        //div an luu du lieu tam
        $mform->addElement('html','<div style="display: none">');
            $mform->addElement('text', 'txtid', 'ID_survey', $attributes);
            $mform->setDefault('txtid',$survey_id);
            $mform->addElement('text', 'txtid_g_in', 'ID_guide_in', $attributes);
            $mform->setDefault('txtid_g_in',$id_guide_input);
            $mform->addElement('text', 'txtid_g_out', 'ID_guide_out', $attributes);
            $mform->setDefault('txtid_g_out',$id_guide_output);
            $mform->addElement('text', 'txtid_pro', 'ID_program', $attributes);
            $mform->setDefault('txtid_pro',$program_id);
            //$mform->addElement('text', 'txt_temp_ques', 'temp_ques', $attributes);
            //$mform->setDefault('txt_temp_ques',$ques_selected);
        $mform->addElement('html','</div>');
        
        //submit button
		$mform->addElement('submit', 'submitbutton', get_string('save_change1', 'local_blackboxsurvey'),array('id'=>'submitbutton','style'));
		$mform->closeHeaderBefore('submitbutton');                                                                                                       
	}
}

//Form hien thi add question trong create and edit survey
class form_add_survey_question extends moodleform {
	public function definition() {
		$mform = $this->_form;
        $str = $this->_customdata['str'];
        $survey_id = $this->_customdata['survey_id'];
		$mform->addElement('html','<div id="questiontable">'.$str.'</div>');
        //div an luu du lieu tam
        $mform->addElement('html','<div style="display: none">');
            $mform->addElement('text', 'txtid', 'ID_survey', $attributes);
            $mform->setDefault('txtid',$survey_id);
        $mform->addElement('html','</div>');
	}
}

//Form hien thi add question trong create and edit survey
class form_add_survey_question_edit_only extends moodleform {
	public function definition() {
		$mform = $this->_form;
        $str = $this->_customdata['str'];
        //$survey_id = $this->_customdata['survey_id'];
        $array_ques = $this->_customdata['array_ques'];
        $survey_id = $this->_customdata['survey_id'];
        
		$mform->addElement('html','<div id="questiontable">'.$str.'</div>');
        //div an luu du lieu tam
        $mform->addElement('html','<div style="display: none">');
        $mform->addElement('text', 'txtquestion', 'ques_array', $attributes);
        $mform->setDefault('txtquestion',$array_ques);
        $mform->addElement('text', 'txtid', 'survey id', $attributes);
        $mform->setDefault('txtid',$survey_id);
        $mform->addElement('html','</div>');
	}
}
//******************************************************************************************************************************************************************
//                                                                              FORM QUESTION MANAGEMENT
//******************************************************************************************************************************************************************
//Form manage question
class form_manage_question extends moodleform {
	public function definition() {
		$mform = $this->_form;
		$mform->addElement('html', '<h1>'.get_string('question_management', 'local_blackboxsurvey').'</h1>');
	}
}

//Form hien thi question
class form_questionlist extends moodleform {
	public function definition() {
		$mform = $this->_form;
        
        $str = $this->_customdata['str'];
        //echo "<script>alert('".$str."');</script>";
        $mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
		$mform->addElement('html','<div id="questiontable" style="display: none;">'.$str.'</div>');
	}
}

//Form hien thi survey
class form_surveylist extends moodleform {
	public function definition() {
		$mform = $this->_form;
        
        $str = $this->_customdata['str'];
        //echo "<script>alert('".$str."');</script>";
        $mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
		$mform->addElement('html','<div id="survey_able" style="display: none;">'.$str.'</div>');
	}
}

//form question 1 loai dap an
class form_add_single_answer_question extends moodleform {
    
	public function definition() {
	    global $DB;
		$mform = $this->_form;
        $typeid = $this->_customdata['id'];
        $mform->addElement('html','<div class="headingblock header">'.get_string('new_question', 'local_blackboxsurvey').'</div>');
        $mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
        //load loai cau hoi
        $mform->addElement('html','<div id="content" style="display: none">');
        $temp = new b_question_type();
        $options = $temp->load_question_type();
		$select = $mform->addElement('select', 'question_type', get_string('question_type', 'local_blackboxsurvey'), $options, array('id'=>'cboquestype','onChange'=>'load_question_form();'));
        if($typeid != "") {
			$mform->setDefault('question_type', $typeid);
		}
        
        //noi dung cau hoi
		$mform->addElement('htmleditor', 'txtcont', get_string('question_content', 'local_blackboxsurvey'));
		$mform->setType('txtcont', PARAM_CLEANHTML);
        $mform->addRule('txtcont', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        
        
		//submit
		$mform->addElement('submit', 'submitbutton', get_string('new_question', 'local_blackboxsurvey'), array('id'=>'submitbutton','style'=>''));
        $mform->addElement('html','</div>');
		$mform->closeHeaderBefore('submitbutton');
        
    }
}
//Form multi choice question
class form_add_multi_choice_question extends moodleform {
    
	public function definition() {
	    
		$mform = $this->_form;
        
        $typeid = $this->_customdata['id'];
        $path_image = $this->_customdata['path_image'];
        
        $mform->addElement('html','<div class="headingblock header">'.get_string('new_question', 'local_blackboxsurvey').'</div>');
        $mform->addElement('html','<div id="lodiv" style="display: none;"><div id="mess" class="success" ></div></div>');
        
        //load loai cau hoi
        $mform->addElement('html','<div id="content" style="display: none">');
        $temp = new b_question_type();
        $options = $temp->load_question_type();
		$select = $mform->addElement('select', 'question_type', get_string('question_type', 'local_blackboxsurvey'), $options, array('id'=>'cboquestype','onChange'=>'load_question_form();'));
        if($typeid != "") {
			$mform->setDefault('question_type', $typeid);
		}
        
        //noi dung cau hoi
		$mform->addElement('htmleditor', 'txtcont', get_string('question_content', 'local_blackboxsurvey'));
		$mform->setType('txtcont', PARAM_CLEANHTML);
        $mform->addRule('txtcont', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        
        //div add/remove textbox option
        $mform->addElement('html','<table><tr><td valign=top><pre>                       </pre></td><td>');
		
		
        $default_opt = 2;//so option mac dinh
        $mform->addElement('html', '<div id="TextBoxesGroup">');
        for($i=1;$i<=$default_opt;$i++){
            $mform->addElement('html', '<div id="TextBoxDiv'.$i.'">
                           <input type="text" id="txtOpt'.$i.'" placeholder="Option '.$i.'" size="80" onblur="check_all_textbox()"/>
                           <img style="cursor:pointer;" src="'.$path_image.'delete.png" onclick="remove_textbox('.$i.');"/>
	                       </div>');
        }
        $mform->addElement('html', '</div>');
        //div hien require option field                           
        $mform->addElement('html', '<div id="divCheck" class="error">'.get_string('blank3', 'local_blackboxsurvey').'</div>');
        
        $mform->addElement('html','</td></tr></table>');
        
        //button tao option moi
        $mform->addElement('button', 'add_txt', get_string('add_option', 'local_blackboxsurvey'), array('id'=>'addButton','onClick'=>'add_textbox();'));
         
        //submit
		$mform->addElement('submit', 'submitbutton', get_string('new_question', 'local_blackboxsurvey'), array('id'=>'submitbutton','style'=>''));
        $mform->addElement('html','</div>');//end div content
		$mform->closeHeaderBefore('submitbutton');
		
        //div an cac du lieu luu tam
        $mform->addElement('html','<div id="divSubCheck" style="display: none">');
            
            //luu tam option cua cau hoi
            $mform->addElement('html','<div id="div_arr_opt"></div>');
            //$mform->addElement('textarea', 'opt_cache', '', 'wrap="virtual" rows="20" cols="50"');//save tam options cua cau hoi
            $mform->addElement('html', '<input id="id_counter" name="counter" type="text" value="'.$default_opt.'"/>');//save so opt da tao
            
            $mform->addElement('text', 'txtCheck', 'check opt', $attributes='size="40"', array('id'=>'txtCheck'));//kiem tra dien full option 
    		$mform->setType('txtCheck', PARAM_TEXT);
    		$mform->addRule('txtCheck', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        
        $mform->addElement('html','</div>');
    }
}

//form hien thi cau hoi
class form_view_short_question extends moodleform {
    
	public function definition() {
		$mform =& $this->_form;
        
        //load cau hoi
        $ques_id = $this->_customdata['id'];;
		$ques_content = $this->_customdata['content'];
        $ques_type = $this->_customdata['type'];
        //hien cau hoi
        $mform->addElement('html','<h2>'.$ques_content.'</h2>');
        $mform->addElement('html','<p>'.get_string('question_answer', 'local_blackboxsurvey').'</p>');
        //hi?n khung tra l?i cau h?i
        if($ques_type == 1)
        {
            $mform->addElement('textarea', 'opt_cache', '', 'wrap="virtual" rows="5" cols="30"');    
        }
        //multichoice question - many answer - checkbox
        elseif($ques_type == 2)
        {
            
            $n = $this->_customdata['num_opt'];
            for($i = 1;$i<=$n;$i++)
            {
                $opt_id = $this->_customdata['opt_id'.$i];
                $opt_content = $this->_customdata['opt_ct'.$i];
                $mform->addElement('advcheckbox', 'opt'.$i, '', $opt_content, array('group' => 1),  $opt_id);
            }
            
        }
        //multichoice question - single answer - radio
        elseif ($ques_type == 3)
        {
            $n = $this->_customdata['num_opt'];
            $radioarray=array();
            for($i = 1;$i<=$n;$i++)
            {
                $opt_id = $this->_customdata['opt_id'.$i];
                $opt_content = $this->_customdata['opt_ct'.$i];
                $radioarray[] =& $mform->createElement('radio', 'opt', '', $opt_content, $opt_id, $attributes);
            }
            $mform->addGroup($radioarray, 'radioar', '', array('<br>'), false);
        }
        //hien yes no question
        elseif ($ques_type == 4)
        {
            $mform->addElement('selectyesno', 'maxbytes');
        }
    }
}
/**
 * Form dung cho edit question
 */
class form_edit_question extends moodleform{

	public function definition () {
        $mform =& $this->_form;
        
        //lay cac data cua cau hoi
        $ques_id = $this->_customdata['id'];
        $ques_content = $this->_customdata['content'];
        
        //noi dung cau hoi
		$mform->addElement('htmleditor', 'txtcont', get_string('question_content', 'local_blackboxsurvey'));
		$mform->setType('txtcont', PARAM_CLEANHTML);
        $mform->addRule('txtcont', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        $mform->setDefault('txtcont',$ques_content);
        
        //start hiden div
        $mform->addElement('html','<div id="divSubCheck" style="display: none">');
        
        //luu lai id 
        $mform->addElement('text', 'txtid', 'ID', $attributes='size="40"');
        $mform->setDefault('txtid',$ques_id);
        
        //end hidden div
        $mform->addElement('html','</div>');
        
        //submit
		$mform->addElement('submit', 'submitbutton', get_string('save_change1', 'local_blackboxsurvey'), array('id'=>'submitbutton','style'=>''));
		$mform->closeHeaderBefore('submitbutton');

	}
}
/**
 * Form dung cho edit multichoice question
 */
class form_edit_multichoice_question extends moodleform{

	public function definition () {
        $mform =& $this->_form;
        
        //lay cac data cua cau hoi
        $ques_id = $this->_customdata['id'];
        $path_image = $this->_customdata['path_image'];
        $ques_content = $this->_customdata['content'];
        
        //noi dung cau hoi
		$mform->addElement('htmleditor', 'txtcont', get_string('question_content', 'local_blackboxsurvey'));
		$mform->setType('txtcont', PARAM_CLEANHTML);
        $mform->addRule('txtcont', ''.get_string('blank2e', 'local_blackboxsurvey').'', 'required', null, 'client');
        $mform->setDefault('txtcont',$ques_content);
        
        //div add/remove textbox option
        $mform->addElement('html','<table><tr><td valign=top><pre>                </pre></td><td>');
        
        $mform->addElement('html', '<div id="TextBoxesGroup">');
        $n = $this->_customdata['num_opt'];
        for($i = 1;$i<=$n;$i++)
        {
            $opt_id = $this->_customdata['opt_id'.$i];
            $opt_content = $this->_customdata['opt_ct'.$i];
            $mform->addElement('html', '<div id="TextBoxDiv'.$i.'">
                       <input type="text" id="txtOpt'.$i.'" placeholder="Option '.$i.'" size="80" value="'.$opt_content.'" onblur="check_all_textbox()"/>
                       <img style="cursor:pointer;" src="'.$path_image.'delete.png" onclick="remove_textbox('.$i.');"/>
                       </div>');
        }
        
        $mform->addElement('html', '</div>');
        $mform->addElement('html', '<div id="divCheck" class="error">'.get_string('blank3', 'local_blackboxsurvey').'/div>');//div hien require option field 
        
        $mform->addElement('html','</td></tr></table>');
        
        //button tao option moi
        $mform->addElement('button', 'add_txt', get_string('add_option', 'local_blackboxsurvey'), array('id'=>'addButton','onClick'=>'add_textbox();'));
        
        //div an cac du lieu luu tam
        $mform->addElement('html','<div id="divSubCheck" style="display: none">');
        //luu lai id va dang cau hoi
            $mform->addElement('text', 'txtid', 'ID', $attributes='size="40"');
            $mform->setDefault('txtid',$ques_id);
        
            //luu tam option cua cau hoi
            $mform->addElement('html','<div id="div_arr_opt"></div>');
            //$mform->addElement('textarea', 'opt_cache', '', 'wrap="virtual" rows="20" cols="50"');//save tam options cua cau hoi
            
            $mform->addElement('html', '<input id="id_counter" name="counter" type="text" value="'.$n.'"/>');//save so opt da tao
            
            //kiem tra dien full option 
            $mform->addElement('text', 'txtCheck', 'check opt', $attributes='size="40"', array('id'=>'txtCheck'));
            $mform->setType('txtCheck', PARAM_TEXT);
            $mform->addRule('txtCheck', get_string('blank2', 'local_blackboxsurvey'), 'required', null, 'client');
        $mform->addElement('html', '</div>');
        
        //submit
		$mform->addElement('submit', 'submitbutton', get_string('save_change1', 'local_blackboxsurvey'), array('id'=>'submitbutton','style'=>''));
		$mform->closeHeaderBefore('submitbutton');

	}
}